<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            background-color: pink;
            color: #000;
        }

        .change {
            background-color: purple;
            font-size: 22px;
            color: #fff;
            margin: 100px auto;
            text-align: center;
            line-height: 200px;
        }
    </style>
</head>

<body>
    <div class="one">样式</div>
    <script>
        //获取元素
        var test = document.querySelector('div');
        //注册事件  处理程序
        test.onclick = function () {
            this.className = 'one change'
        }
    </script>
</body>

</html>